<!-- 横向布局 -->
<template>
	<el-container class="layout-transverse">
		<el-header :style="{ height: headerHeight + 'px' }">
			<div class="logo flx-center">
				<img v-if="!!sideLogo" :src="sideLogo" alt="logo" />
				<span>{{ systemTitle }}</span>
			</div>
			<el-menu
				mode="horizontal"
				:default-active="activeMenu"
				:router="false"
				:unique-opened="true"
				:background-color="headerBgColorGet"
				:text-color="headerTextColorGet"
				active-text-color="#ffffff"
			>
				<!-- 只有在这里写 submenu 才能触发 menu 三个点省略 -->
				<template v-for="subItem in menuList" :key="subItem.path">
					<el-sub-menu v-if="subItem.children?.length" :index="subItem.path" :key="subItem.path + 'el-sub-menu'">
						<template #title>
							<el-icon>
								<component :is="subItem.meta.icon"></component>
							</el-icon>
							<span>{{ subItem.meta.title }}</span>
						</template>
						<SubMenu :menuList="subItem.children" />
					</el-sub-menu>
					<el-menu-item v-else :index="subItem.path" :key="subItem.path + 'el-menu-item'" @click="handleClickMenu(subItem)">
						<el-icon>
							<component :is="subItem.meta.icon"></component>
						</el-icon>
						<template #title>
							<span>{{ subItem.meta.title }}</span>
						</template>
					</el-menu-item>
				</template>
			</el-menu>
			<ToolBarRight />
		</el-header>
		<Main />
	</el-container>
</template>

<script setup lang="ts" name="layoutTransverse">
import { computed } from 'vue'
import { AuthStore } from '@/stores/modules/auth'
import { GlobalStore } from '@/stores'
import { useRoute, useRouter } from 'vue-router'
import Main from '@/layouts/components/Main/index.vue'
import ToolBarRight from '@/layouts/components/Header/ToolBarRight.vue'
import SubMenu from '@/layouts/components/Menu/SubMenu.vue'

const route = useRoute()
const router = useRouter()
const authStore = AuthStore()
const globalStore = GlobalStore()
const activeMenu = computed(() => route.path)
const menuList = computed(() => authStore.showMenuListGet)
const headerHeight = computed(() => globalStore.themeConfig.headerHeight)
const sideLogo = computed(() => globalStore.themeConfig.sideLogo)
const systemTitle = computed(() => globalStore.themeConfig.systemTitle)
const headerBgColorGet = computed(() => globalStore.headerBgColorGet)
const headerTextColorGet = computed(() => globalStore.headerTextColorGet)

const handleClickMenu = (subItem: Menu.MenuOptions) => {
	if (subItem.meta.isLink) window.open(subItem.meta.isLink, '_blank')
	router.push(subItem.path)
}
</script>

<style scoped lang="scss">
@import './index.scss';
</style>

<style lang="scss">
.transverse {
	// 横向菜单布局
	.el-menu--horizontal {
		.el-menu-item,
		.el-sub-menu {
			height: 54px !important;
			transition: none;
			.el-sub-menu__title {
				height: 100%;
			}
		}
		.el-menu-item:hover {
			background: var(--el-color-primary-light-9);
		}
	}
	&.rect {
		.el-menu {
			.is-active {
				background-color: var(--el-color-primary) !important;
				.el-sub-menu__title {
					color: #ffffff !important;
					background-color: var(--el-color-primary) !important;
				}
				&:hover {
					color: #ffffff !important;
				}
			}
		}
		.el-popper {
			.el-menu,
			.el-menu--popup {
				.el-menu-item {
					&:hover,
					&.is-active {
						color: var(--el-color-primary) !important;
						background: var(--el-color-primary-light-9) !important;
						&::before {
							position: absolute;
							top: 0;
							bottom: 0;
							left: 0;
							width: 4px;
							content: '';
						}
					}
					&.is-active::before {
						background: var(--el-color-primary);
					}
				}
				.el-sub-menu {
					&.is-active,
					.el-sub-menu__title {
						background-color: transparent !important;
					}
				}
			}
		}
	}
	&.round {
		.el-menu-item:focus,
		.el-menu-item:hover {
			background: transparent;
		}
		.el-sub-menu,
		.el-menu-item {
			position: relative;
			&::before {
				position: absolute;
				top: calc(50% - 20px);
				right: 5px;
				left: 5px;
				width: auto;
				height: 40px;
				margin: auto;
				content: '';
				background: transparent;
				border-radius: var(--sloth-side-menu-radius);
			}
			.el-sub-menu__title {
				background: transparent !important;
			}
			> span {
				position: relative;
			}
		}
		.el-sub-menu:hover,
		.el-menu-item:hover {
			&::before {
				background: var(--sloth-menu-item-hover-color);
			}
		}
		.el-menu {
			.is-active {
				color: #ffffff !important;
				background: transparent !important;
				&::before {
					background: var(--sloth-menu-active-bg);
				}
				> span {
					position: relative;
				}
			}
		}
		.el-popper {
			.el-menu,
			.el-menu--popup {
				.el-menu-item {
					&:hover,
					&.is-active {
						background: transparent !important;
						> span {
							position: relative;
						}
					}
				}
				.is-active {
					&::before {
						background: var(--el-color-primary-light-9) !important;
						opacity: 1;
					}

					color: var(--el-color-primary) !important;
				}
			}
		}
	}
	.el-popper {
		.el-sub-menu.is-active {
			.el-sub-menu__title {
				color: var(--el-color-primary) !important;
			}
		}
	}

	// guide
	#driver-highlighted-element-stage {
		background-color: #606266 !important;
	}
}
</style>
